
proc hlm { args } {
	parse_proc_arguments -args $args arg
	if {[info exist arg(-macro_list)] && [$arg(-macro_list) ne ""]} {
		set all_blocks $arg(-macro_list)
	} else {
		set all_blocks [get_db [get_db insts -if {.base_cell.class == block  && .is_physical == false}] .name]
	}
	if {[info exist arg(-level)] && ($arg(-level) > 0)} {
		set level $arg(-level)
	} else {set level 3}
	set hier_list {}
	foreach block ${all_blocks} {
		lappend hier_list [join [lrange [split ${block} /] 0 [expr ${level} -1] ] /]
	}	
	set hier_list [lsort -u $hier_list]
	set hier_num [llength ${hier_list}]
	for {set i 0} {${i} < ${hier_num}} {incr i 1} {
		set cur_block_hier [lindex ${hier_list} ${i}]
		selectInst [dbget [dbget top.insts.cell.baseClass block -p2].name $cur_block_hier*]
		highlight -index [expr $i + 1]
		deselectAll
	}
	## output memory groups info
	if {[info exist arg(-outfile)] && ($arg(-outfile) ne "")} {
		set memGroupFile "$arg(-outfile)"
		set fi [open $memGroupFile w+]
		for {set i 0} {$i <= 64} {incr i} {
			if {[dbForEachHeadHilitePtr [dbgHead] $i obj { get_db [get_db insts $obj.name] .name }] != "" } {
			puts $fi "[dbForEachHeadHilitePtr [dbgHead] $i obj { puts $fi "[get_db [get_db insts $obj.name] .name] \\"}]\n#"
			}
		}
		close $fi
	}
	puts "highlight finished"
}

define_proc_arguments hlm \
	-info "highlight macros by hier level and output macro division info" \
	-define_args {
	{-macro_list "highlight the defined macro list.default all macros " "" list optional} \
	{-level "highlight levels,default levels 3" "" string optional} \
	{-outfile "specify the output file for memory groups info" "" string optional}								
} 

